package com.shuoyutech.dp.job;

import com.alibaba.fastjson.JSON;
import com.shuoyutech.dp.entity.HealthCheck;
import com.shuoyutech.dp.service.IHealthCheckService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Slf4j
@Component
public class HealthCheckJob {

    @Autowired
    private IHealthCheckService healthCheckService;

    @Scheduled(cron = "0/1 * * * * ?")
    public void job () {
        HealthCheck healthCheck = healthCheckService.checkHealth();
        log.info("[TEST-JOB] {} {}", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")), JSON.toJSON(healthCheck));
    }
}
